<template>
  <div class="home-view">
    <van-image class="background-image" :src="require('@/assets/zxxq_bg@2x.png')" />

    <van-nav-bar fixed title="开课认证">
      <template #left>
        <div>
          <img src="../../../assets/gzt_nav_ico_close@2x.png" alt="" class="logo" />
        </div>
      </template>
    </van-nav-bar>
    <div class="status-box">
      <div class="item">
        <!-- <div class="item-title tit-txt">
          <img src="../../../assets/dd_xq_ico_jbxx@2x.png" alt="" class="top-icon" />
          认证结果有效
        </div> -->
      </div>
    </div>
    <div class="top-box">
      <div class="top-card">
        <van-cell-group>
          <div class="item">
            <div class="item-title tit-txt">
              <img src="../../../assets/dd_xq_ico_jbxx@2x.png" alt="" class="top-icon" />
              基本信息
            </div>
          </div>
          <van-cell title="名称" value="内容" />
          <van-cell title="学段" value="内容" />
          <van-cell title="年级" value="内容" />
          <van-cell title="班级" value="内容" />
          <van-cell title="学科 " value="内容" />
          <van-cell title="授课教师" value="内容内容内容内容内容内容内容" />
          <van-cell title="授课教室" value="内容" />
          <van-cell title="授课时间" value="内容" />
        </van-cell-group>
      </div>
    </div>
    <div class="img-box">
      <div class="top-card">
        <div class="item">
          <div class="item-title tit-txt">
            <img src="../../../assets/card@2x.png" alt="" class="top-icon" />
            认证图片
          </div>
          <div class="item-title desc">开课集体照<span class="tips">（限1张）</span></div>
          <div class="imgList-card">
            <van-uploader v-model="fileList1" multiple :max-count="1"  v-if="isComponentVisible">
              <img src="../../../assets/add-icon.png" alt="" class="addBox"
            /></van-uploader>
              <div class="uploaded-images" v-else>
                <div v-for="(item, index) in fileList1" :key="index" class="image-item">
                  <img :src="item.content" alt=""  />
                </div>
              </div>
          </div>
          <div class="item-title desc">课程照片 <span class="tips">（限9张）</span></div>
          <div class="imgList-card">
            <van-uploader v-model="fileList" multiple :max-count="9" v-if="isComponentVisible">
              <img src="../../../assets/add-icon.png" alt="" class="addBox"
            /></van-uploader>
               <div class="uploaded-images" v-else>
                <div v-for="(item, index) in fileList" :key="index" class="image-item">
                  <img :src="item.content" alt=""  />
                </div>
              </div>
          </div>
          <div class="item-title desc">学生照片<span class="tips">（限9张）</span></div>
          <div class="imgList-card">
            <!--  -->
            <div>
              <van-uploader
                v-model="images"
                :after-read="afterRead"
                :max-count="9"
                multiple
                class="preBox"
                v-if="isComponentVisible"
              >
                <img src="../../../assets/add-icon.png" alt="" class="addBox" />
              </van-uploader>
              <div class="uploaded-images" v-if="isComponentVisible">
                <div v-for="(item, index) in images" :key="index" class="image-item">
                    <img :src="item.content" alt="" @click="showImage(index)" />
                  <img
                    @click.stop="removeImage(index)"
                    src="../../../assets/close-icon.png"
                    class="close-btn"
                  />
                  <!-- 删除按钮 -->
                  <van-field
                    v-model="item.name"
                    placeholder="请输入图片名称"
                    class="inputbox"
                  />
                </div>
              </div>
                 <div class="uploaded-images" v-else>
                <div v-for="(item, index) in images" :key="index" class="image-item">
                     <img :src="item.content" alt=""  />
                  <div
                   
                    class="name-box"
                  >{{item.name}}</div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <van-button type="info" block @click="submit" class="submitBox"  v-if="isComponentVisible">提交</van-button>
    </div>
  </div>
</template>

<script>
import { RadioGroup, Radio, Checkbox } from "vant";
import { userAPI } from '@/api/index.js'
import { removeToken } from '@/utils/token.js'
export default {
  components: {
    VanRadioGroup: RadioGroup, // 注册 RadioGroup 组件
    VanRadio: Radio, // 注册 Radio 组件
    VanCheckbox: Checkbox,
  },
  data() {
    return {
      userObj: {},
      isComponentVisible: true, // 控制组件是否可见
      images: [],
      fileList: [
      ],
      fileList1: [],
    };
  },
    async activated () {
    const res = await userAPI()
    this.userObj = res.data.data
    // 直接调用mutations的方法
    // this.$store.commit('SET_USERPHOTO', this.userObj.photo)
    // this.SET_USERPHOTO(this.userObj.photo)
  },
  methods: {
    afterRead(file) {
      if (this.images.some((f) => f.file === file.file)) {
        // 如果文件已经存在于 images 中，则不重复添加
        return;
      }
      file.name = ""; // 初始化图片名称为空
      this.images.push(file);
    },
    removeImage(index) {
      this.images.splice(index, 1); // 移除指定索引处的图片
    },
    showImage(index) {
      // 这里可以添加查看大图的功能
      console.log("点击了第", index, "个图片");
    },
    submit() {
      this.isComponentVisible=false
       console.log(this.fileList,this.fileList1,this.images);
    },
  },
};
</script>

<style scoped lang="less">
img {
  display: block;
}
.home-view {
  background: #f3f3f3;
  position: relative;
  padding-bottom: 1.3333rem;
  .background-image {
    width: 100%;
    height: 8.9867rem; // 根据需要设置高度
    position: absolute;
    background-size: cover;
    background-position: center;
  }
  .logo {
    width: 0.72rem;
    height: 0.72rem;
    vertical-align: middle;
  }
  .status-box {
    position: relative;
    z-index: 1;
    padding: 1.0667rem 0.32rem 0;

    box-sizing: border-box;
    .item {
      height: 1.3867rem;
      .item-title {
        font-weight: 600;
        font-size: 0.48rem;
        color: #ffffff;
        line-height: 0.6667rem;
      }
      .tit-txt {
        display: flex;
        align-items: center;
        height: 1.3867rem;
        .top-icon {
          width: 0.6667rem;
          height: 0.7733rem;
          margin-right: 0.16rem;
        }
      }
    }
  }
  .top-box {
    padding: 0.32rem 0.32rem 0;

    box-sizing: border-box;

    .top-card {
      border-radius: 0.2667rem;
      background: #fff;
      padding: 0.2133rem;
      position: relative; // 添加此行
      z-index: 1; // 添加此行
      .item {
        padding: 0 0.2667rem;
        .item-title {
          font-weight: 400;
          font-size: 0.3733rem;
          color: #080808;
          line-height: 0.5333rem;
          // line-height: 0.7467rem;
        }
        .tit-txt {
          display: flex;
          align-items: center;
          height: 1.3867rem;
          border-bottom: 1px solid #f3f3f3;
          .top-icon {
            width: 0.7467rem;
            height: 0.7467rem;
            margin-right: 0.16rem;
          }
        }
      }
    }
  }
  .img-box {
    padding: 0.2667rem 0.32rem 0;

    box-sizing: border-box;

    .top-card {
      border-radius: 0.2667rem;
      background: #fff;
      padding: 0.2133rem 0.2133rem 1.3333rem 0.2133rem;
      position: relative; // 添加此行
      z-index: 1; // 添加此行
      .item {
        padding: 0 0.2667rem;
        .item-title {
          font-weight: 400;
          font-size: 0.3733rem;
          color: #080808;
          line-height: 0.5333rem;
          // line-height: 0.7467rem;
        }
        .tit-txt {
          display: flex;
          align-items: center;
          height: 1.3867rem;
          border-bottom: 1px solid #f3f3f3;
          .top-icon {
            width: 0.7467rem;
            height: 0.7467rem;
            margin-right: 0.16rem;
          }
        }
        .desc {
          padding: 0.2667rem 0;
          .tips {
            color: #bfbfbf;
          }
        }
      }
    }
  }
}
.van-cell::after {
  border: none;
}
.van-cell,
.van-cell__value {
  font-weight: 400;
  font-size: 0.3733rem;
  color: #080808;
  line-height: 0.5333rem;
}
.van-cell--large .van-cell__title {
  font-size: 0.3733rem;
  font-weight: 500;
  line-height: 0.7467rem;
  color: #080808;
}
/deep/ .van-cell-group {
  border-radius: 0.2667rem !important;
}
[class*="van-hairline"]::after {
  border: none !important;
}
/deep/ .van-nav-bar {
  background: none !important;
  border: none !important;
}
/deep/ .van-nav-bar__title {
  font-weight: 500;
  font-size: 0.4533rem;
  color: #ffffff;
}
/deep/ .van-nav-bar__content {
  height: 1.4133rem !important;
  line-height: 1.4133rem !important;
}

/deep/ .van-icon__image {
  width: 0.5333rem;
  height: 0.5333rem;
}
.van-nav-bar {
  background-color: #007bff;
}
.uploaded-images {
  display: -ms-flexbox;
  display: flex;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
  gap: 10px; /* 列间距 */
}

.image-item {
  width: 2.4533rem;
  position: relative; /* 设置相对定位以便于绝对定位子元素 */
}

.image-item img {
  width: 2.4533rem;
  height: 2.4533rem;
  cursor: pointer; /* 点击样式 */
}

.image-item .close-btn {
  position: absolute; /* 绝对定位 */
  top: 0.1333rem; /* 调整位置 */
  right: 0.1333rem;
  width: 0.5333rem;
  height: 0.5333rem;
  border-radius: 50%; /* 圆形按钮 */

  cursor: pointer;
}

.van-button--info {
  background-color: #2dabff; /* 自定义颜色 */
  color: white;
}
.submitBox {
  margin-top: 1.0667rem;
  background: #05AFEA;
border-radius: 22px;
}
.uploaded-images {
  margin-top: 0.2667rem;
}
.inputbox {
  margin-top: 0.2667rem;
  padding: 0.0533rem;
  border: 1px solid #bfbfbf;
  border-radius: 0.2667rem;

  /deep/ .van-field__control {
    text-align: center;
  }
}
.name-box{
  font-size: .3733rem;
  text-align: center;
   margin-top: 0.2667rem;
  padding: 0.0533rem;
}
/deep/ .van-uploader__input-wrapper {
  width: 2.4533rem;
  height: 2.4533rem;
  // margin-right: .2667rem;
}
// /deep/  .van-uploader__wrapper{
//   flex-direction: row-reverse ;
// }
/deep/ .van-uploader__input-wrapper img {
  width: 100%;
  height: 100%;
}
.van-uploader__input {
}
/deep/ .van-uploader__preview-image {
  width: 2.4533rem;
  height: 2.4533rem;
}
.preBox /deep/ .van-uploader__preview {
  display: none !important;
}
/deep/ .van-uploader__preview-delete{
  width: 0.5333rem;
  height: 0.5333rem;
  border-radius: 50%;
  top:.1067rem; /* 调整位置 */
  right: .08rem;
}
/deep/ .van-uploader__preview-delete-icon{
  font-size: .5333rem;
  right: 0;
  top: 0;
  font-weight: 500;

}
@media (min-width: 768px) {
  .home-view .background-image {
    background-image: url("../../../assets/login_bg@3x.png"); // 宽屏幕背景图
  }
}

@media (max-width: 767px) {
  .home-view .background-image {
    background-image: url("../../../assets/login_bg@2x.png"); // 窄屏幕背景图
  }
}
</style>
